<?php
namespace Qgs\Controller;

/**
 * 会员投诉
 * Class MemberComplainController
 * @package Qgs\Controller
 */
class MemberComplainController extends BaseController
{
    public $local_id;

    public function __construct()
    {
        parent::__construct();
        $this->local_id = session('userInfo')['local_id'];
    }

    public function index()
    {
        $b2c_order_complain = M('b2c_order_complain');
        $where = [
            'local_id' => $this->local_id,
            'pid' => '0'
        ];
        $complain = $b2c_order_complain->where([$where])->select();

        $this->assign([
            'complain' => $complain
        ]);
        $this->display();
    }

    public function delete(){
        $b2c_order_complain = M('b2c_order_complain');
        $id= I('id', '', htmlspecialchars());
        $b2c_order_complain->where(['id' => $id])->delete();
        $this->redirect('MemberComplain/index');
    }

    /**
     * 回复投诉
     */
    public function replay(){
        $content = I('content', '', htmlspecialchars());
        $name = I('name', '', htmlspecialchars());
        $id = I('id', '', intval());
        $b2c_order_complain = M('b2c_order_complain');
        $data = [
          'operation_name' =>  $name,
            'message' => $content,
            'pid' => $id
        ];
        $complain = $b2c_order_complain->add($data);
        $complain_save = $b2c_order_complain->where(['id'=>$id])->setField('is_reply', 'true');
        if ($complain && $complain_save) {
            echo 1;exit;
        }
        echo 0;
    }

    /**
     * 查看
     */
    public function look(){
        $id = I('id', '', intval());
        $b2c_order_complain = M('b2c_order_complain');
        $complain = $b2c_order_complain->where(['pid' => $id])->select();
        echo json_encode([
           'msg' => $complain
        ]);
    }


}